package com.lxy.aimin.satoken.user;

import cn.dev33.satoken.stp.SaLoginModel;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpLogic;
import com.lxy.aimin.satoken.Device;

public class StpUserUtil {

    /**
     * 账号体系标识
     */
    public static StpLogic stpLogic = new StpLogic("USER");    // 将 LoginType 从`login`改为`user`




    public static void loginByPc(String openId) {
        SaLoginModel config = new SaLoginModel();
        config.setDevice(Device.PC);
        config.setIsWriteHeader(false);
        stpLogic.login(openId, config);
    }

    public static SaTokenInfo loginByMiniProgram(String openId) {
        SaLoginModel config = new SaLoginModel();
        config.setDevice(Device.MINI_PROGRAM);
        config.setIsWriteHeader(false);
        stpLogic.login(openId, config);
        return getTokenInfo();
    }

    /**
     * 获取当前请求的令牌信息
     *
     * @return 当前请求的令牌信息如果当前请求没有关联的令牌，或者令牌解析失败，将返回null
     */
    public static SaTokenInfo getTokenInfo() {
        return stpLogic.getTokenInfo();
    }
}
